<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of HomePage
 *
 * @author juwking
 */
class ClientsPage extends PageController {

    private $clientsContext;
    private $page = 0;

    function __construct() {
        parent::__construct();

        if (isset($_REQUEST["page"])) {
            $this->page = $_REQUEST["page"];
        }
        $this->clientsContext = new ClientsQuery();
        $this->assign('clients', $this->clientsContext->Select($this->page * 30, 30));
        $this->assign('pageNum', $this->page);
    }

    function getPageName() {
        return 'client';
    }

    public function getTemplate() {
        return "client.tpl";
    }

    public function getSidebar() {
        $sidebar = array(
            array(label => 'Dodaj', link => ''),
            array(label => 'Generuj', link => 'randomClients')
        );
        return $sidebar;
    }

    public function Next() {
        $this->page++;
        $this->assign('pageNum', $this->page);
    }
    public function getPage(){
        return $this->page;
    }
    public function Previous() {

        $this->page--;
        $this->assign('pageNum', $this->page);
    }

    function randomClients() {
        $myFile = "names";
        $fh = fopen($myFile, 'r');
        $theData = fread($fh, filesize($myFile));
        fclose($fh);
        $nameArray = explode(" ", $theData);
        $arrayCount = count($nameArray);
        for ($it = 0; $it < 1; $it++) {

            $name = $nameArray[rand(0, $arrayCount)];
            $surname = $nameArray[rand(0, $arrayCount)];
            $record = array('client_categories_id' => 1, 'client_organization_id' => null, 'name' => $name, 'surname' => $surname, 'gender' => rand(0, 1), 'age' => rand(0, 80), 'email' => $name . '@' . $surname . '.com', 'status' => null, 'allowed_binary_code' => null);
            $this->clientsContext->Insert($record);
        }
    }

}

?>
